<template>
    <div class="app-container">

        <!-- 添加或修改家政人员对话框 -->
        <!-- <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body> -->
        <el-row :gutter="20"
                style="margin-top: 12px">
            <el-col>
                <!-- <el-divider content-position="center">家政人员工作经历信息</el-divider> -->
                <el-form ref="form"
                         :model="form"
                         :rules="rules"
                         label-width="80px">
                    <el-table :data="[equipmentData]"
                              @selection-change="handleJzLaborerHistorySelectionChange"
                              ref="jzLaborerHistory">
                        
                        <el-table-column label="姓名"
                                         prop="yhMinUser.uname"></el-table-column>
                        <el-table-column label="电话"
                                         prop="yhMinUser.uphone"></el-table-column>
                        <el-table-column label="性别">
                            <template slot-scope="scope">
                                <span v-if="scope.row.yhMinUser && scope.row.yhMinUser.sex == 0">男</span>
                                <span v-if="scope.row.yhMinUser && scope.row.yhMinUser.sex == 1">女</span>
                                <span v-if="scope.row.yhMinUser && scope.row.yhMinUser.sex == 2">未知</span>
                            </template>

                        </el-table-column>
                        <el-table-column label="年龄"
                                         prop="yhMinUser.age"></el-table-column>
                        <el-table-column label="身高（cm）"
                                         prop="yhMinUser.height"></el-table-column>
                        <el-table-column label="体重（kg）"
                                         prop="yhMinUser.weight"></el-table-column>
                        <el-table-column label="药物类型"
                                         prop="yhDrugCategory.drugCategoryName"></el-table-column>
                        <el-table-column label="最近服用药"
                                         prop="yhMinUser.recentMedication"></el-table-column>
                        <el-table-column label="服用频率"
                                         prop="yhDrugFrequency.drugFrequencyName"></el-table-column>
                        <!-- <el-table-column label="详情"
                                         prop="yhMinUser.age"></el-table-column> -->
                    </el-table>
                </el-form>
            </el-col>
        </el-row>
        <el-row class="item">
            <!-- <el-divider content-position="left">当前设备信息</el-divider> -->
            <el-row class="h1">当前设备信息</el-row>
            <el-card shadow="always">
                <el-row class="equipmentName mt10">{{equipmentData.equipmentName}}</el-row>
                <el-row class="mt10"
                        type="flex">
                    <el-col>型号：{{equipmentData.equipmentModel}}</el-col>
                    <el-col>蓝牙mac地址：{{equipmentData.deviceId}}</el-col>
                </el-row>
                <el-row class="mt10">
                    <el-col>绑定时间：{{equipmentData.createTime}}</el-col>
                </el-row>
                <el-row class="mt10">
                    <!-- 0:绑定、2:解除 -->
                    <el-col v-if="$route.query.delFlag == '2'">解绑时间：{{equipmentData.relieveTime}}</el-col>
                </el-row>
            </el-card>
        </el-row>

        <el-row class="item" v-if="$route.query.delFlag == '0'">
            <!-- <el-divider content-position="left">当前设备信息</el-divider> -->
            <el-row class="h1"
                    type="flex">
                <el-col>运动数据</el-col>
                <el-col>{{equipmentData.relieveTime}}</el-col>
            </el-row>
            <el-card shadow="always">
                <el-row class="mt10"
                        type="flex">
                    <el-col>心率：80次/分</el-col>
                    <el-col>血压：80mmHg</el-col>
                </el-row>
                <el-row class="mt10"
                        type="flex">
                    <el-col>步数：80步</el-col>
                    <el-col>热量：80千卡</el-col>
                </el-row>
                <el-row class="mt10"
                        type="flex">
                    <el-col>血氧：80%</el-col>
                </el-row>
            </el-card>
        </el-row>
    </div>
</template>

<script>
import { listEquipment, getEquipment, addEquipment, updateEquipment, delEquipment } from "@/api/system/equipment";
// let id = 0;
export default {
  name: "EquipmentDetails",
  data() {
    return {
        equipmentData: {},
        imgurl: 'http://192.168.31.230:8080',
        xingbietypes: [
            {
                value: '0',
                label: '男'
            }, {
                value: '1',
                label: '女'
            }
        ],
       fuwutypes: [
        {
          value: '1',
          label: '住家'
        }, {
          value: '2',
          label: '白班'
        }, {
          value: '3',
          label: '钟点工'
        }
      ],
      checkboxGroup1: ['上海'],
      cities: ['06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00',
      '19:00', '20:00', '21:00', '22:00', '23:00'],
      cityarr: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedJzLaborerHistory: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 家政人员表格数据
      laborerList: [],
      // 家政人员工作经历表格数据
      historyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        phone: null,
        serveType: null,
      },
      querysele: '',
      house: '',
      // 表单参数
      form: {
          timesList: [],
          serveMoney: ''
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
      },
      zuo: '',
      jia: '',
      zhao: '',
      lao: ''
    };
  },
  created() {
    // this.getList();
    this.form.id = this.$route.query.id
    this.getdet()
  },
  methods: {
    getdet(){
        const id = this.form.id
        getEquipment(id).then(response => {
            this.form = response.data;
            this.equipmentData = response.data;
        });
    },
    handleChange(value) {
        console.log(value);
    },
    handleChange(value) {
        console.log(value);
    },
    /** 查询家政人员列表 */
    getList() {
      this.loading = true;
      listLaborer(this.queryParams).then(response => {
        this.laborerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
    //   this.open = false;
      this.reset();
      this.$router.push({ path: '/housekeep' })
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        phone: null,
        addressOneId: null,
        addressOneStr: null,
        addressTwoId: null,
        addressTwoStr: null,
        addressThreeId: [],
        addressThreeStr: null,
        addressDetail: null,
        birthData: null,
        age: null,
        sex: null,
        yearNum: null,
        sort: null,
        iconUrl: null,
        serveType: null,
        serveTypeName: null,
        serveMoney: null,
        serveMoneyStr: null,
        tel: null,
        status: 0,
        createId: null,
        createTime: null,
        updateId: null,
        relieveTime: null,
        delFlag: null
      };
      this.historyList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加家政人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEquipment(id).then(response => {
        this.form = response.data;
        this.historyList = response.data.historyList;
        this.open = true;
        this.title = "修改家政人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
        if(this.form.name == '' || this.form.name == undefined){
            this.$message.error('家政人员姓名不能为空！');
            return false
        }
        if(this.form.phone == '' || this.form.phone == undefined){
            this.$message.error('家政人员手机号码不能为空！');
            return false
        }
        this.$refs["form"].validate(valid => {
            if (valid) {
                this.form.historyList = this.historyList;
                if (this.form.id != undefined) {
                    // updateLaborer(this.form).then(response => {
                    //     this.$modal.msgSuccess("修改成功");
                    //     this.open = false;
                    //     this.getList();
                    // });
                } else {
                    // let cons = this.form.contentsList
                    // this.form.contentsList = JSON.stringify(this.form.contentsList)
                    // addLaborer(this.form).then(response => {
                    //     this.$modal.msgSuccess("新增成功");
                    //     this.$router.push({ path: '/housekeep' })
                    // });
                }
            }
        });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除家政人员编号为"' + ids + '"的数据项？').then(function() {
        return delLaborer(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 家政人员工作经历序号 */
    rowJzLaborerHistoryIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 家政人员工作经历添加按钮操作 */
    handleAddJzLaborerHistory() {
      let obj = {};
      obj.laborerTypeStr = "";
      obj.timeStart = "";
      obj.timeEnd = "";
      obj.historyDetail = "";
      obj.createId = "";
      obj.updateId = "";
      this.historyList.push(obj);
    },
    /** 家政人员工作经历删除按钮操作 */
    handleDeleteJzLaborerHistory() {
      if (this.checkedJzLaborerHistory.length == 0) {
        this.$modal.msgError("请先选择要删除的家政人员工作经历数据");
      } else {
        const historyList = this.historyList;
        const checkedJzLaborerHistory = this.checkedJzLaborerHistory;
        this.historyList = historyList.filter(function(item) {
          return checkedJzLaborerHistory.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleJzLaborerHistorySelectionChange(selection) {
      this.checkedJzLaborerHistory = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/laborer/export', {
        ...this.queryParams
      }, `laborer_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.timesss {
	width: 100%;
	margin: 0 auto;
}
.timesss .el-checkbox-group {
	width: 90%;
	margin: 0 auto;
	/* text-align: center; */
}
.el-checkbox-button__inner {
	border: 1px solid #ccc;
	margin-right: 10px;
	margin-top: 10px;
}
.el-input-number {
	width: 130px;
}
.item {
	margin-top: 15px;
}
.h1 {
	font-weight: bold;
}
.equipmentName {
	font-size: 25px;
}
.mt {
	margin-top: 10px;
}
</style>
